#include "OffsideLineBreachBehaviour.h"

// Zoznam informacii o hracoch, ktorych vidi hrac
extern CEvaluatingPlayerList* ePlayerList;

/*
 * Predkopnutie lopty cez hranicu offsajdu
 *
 */
void OffsideLineBreachBehaviour::Behave(float offsideLine)
{
	float fBreachPointOffset = (Point(45, 0) - world->me->pos).GetLength() / 8;

	double lfDribbleX = world->me->pos.GetX();
	double lfDribbleY = world->me->pos.GetY();

	ePlayerList->CalculateOptimalDribblePointAux(lfDribbleX, lfDribbleY, fBreachPointOffset);

	Point breachPoint((float)lfDribbleX, (float)lfDribbleY);
	double lfDistance = (breachPoint - world->me->pos).GetLength();

	double lfPassSpeed = (fabs(lfDistance) - lfMinPassDistance) / (lfMaxPassDistance - lfMinPassDistance) * (world->params->server->ball_speed_max - 1.45) +  1.45;
	
	GetPassBallToBehaviour()->Behave(breachPoint, GetPassBallToBehaviour()->CorrectPassSpeed((float)lfPassSpeed));
	GetTurnNeckToBehaviour()->Behave(breachPoint, world->ball->pos + world->ball->vel, 0);
}
